home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / macabuse / src / smoosh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-20  |  1.4 KB  |  68 lines

  1. #include "jmalloc.hpp"
  2. #define PARTICLE_SIZE 2            // 2x2 block of pixels
  3.  
  4. class particle
  5. {
  6. public :
  7.   unsigned char *pict;
  8.   int x,y;
  9.   particle *left,*right,*up,*down;
  10.   particle(int X, int Y, int size);
  11.   ~particle() { jfree(pict); }
  12. } ;
  13.  
  14. particle::particle(int X, int Y, image *im, int size);
  15.   x=X; y=Y; 
  16.   left=right=up=down=NULL; 
  17.   pict=(unsigned char *)jmalloc(size*size,"Particle");
  18. }
  19.  
  20. class particle_image
  21. {
  22.   int particles;
  23.   particle *top;
  24.   int size;
  25. public :
  26.   particle_image(image *im, int particle_size);       // im will be erased!
  27. } ;
  28.  
  29.  
  30. particle_image::particle_image(image *im, int particle_size)     
  31. {
  32.   int x,y,py,p;
  33.   unsigned char *sl,*sl2;
  34.   top=NULL;
  35.   size=particle_size;
  36.  
  37.   int matw=(im->width()+size-1)/size,math=(im->height()+size-1)/size;
  38.   particle *matrix[matw*math];
  39.  
  40.  
  41.   // break the image up into particles and store in a big matrix
  42.   for (y=0;y<im->height();y++)
  43.   {
  44.     sl=im->scan_line(y);
  45.     py=y/size;
  46.     for (x=0;x<im->width();x++,sl+=px)
  47.     {
  48.       px=x/size;
  49.       sl2=matrix[py*matw+px]->pict+(y%size)*size;      // address of particle image memory
  50.  
  51.       int copy_size;
  52.  
  53.       memset(sl2,0,size);
  54.       
  55.       if (*sl)
  56.       {
  57.     px=x/size;
  58.     py=y/size;
  59.       }
  60.  
  61.   }
  62.   if (px<0)       // couldn't find any non-blank pixels
  63.     particles=0;
  64.   else
  65.     add_particle_line(px,py,im);
  66. }
  67.